package problem.year2023.month04;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author LiangMu
 * @version \$Id: Day25_2.java, v 0.1, 2023年04月27日 16:53 LiangMu Exp $$
 */
public class Day25_2 {

    public static String[] sortPeople(String[] names, int[] heights) {
        int len = names.length;
        Integer[] ints = new Integer[len];
        for (int i = 0; i < len; i++) {
            // 记录 name 的位置
            ints[i] = i;
        }
        // 排序
        Comparator<Integer> comparator = (v1, v2) -> heights[v2] - heights[v1];
        Arrays.sort(ints, comparator);
        String[] result = new String[len];
        for (int i = 0; i < len; i++) {
            result[i] = names[ints[i]];
        }
        System.out.println(Arrays.toString(result));
        return result;
    }

    public static void main(String[] args) {
        // names = ["Mary","John","Emma"], heights = [180,165,170]
        String[] names = {"Mary", "John", "Emma"};
        int[] heights = {180, 165, 170};
        sortPeople(names, heights);
    }
}
